//
//  MOFinishDoDetail_DoingViewController.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/23.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOFinishDoDetail_DoingViewController.h"
#import "MOWaitDoDetail_DoingViewCell.h"
#import "MOWaitDoDetail_Doing_ideaViewCell.h"

@interface MOFinishDoDetail_DoingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;

//打开 关闭(意见)
@property(nonatomic,strong)NSString *openStatus;
//打开 关闭(领导批示)
@property(nonatomic,strong)NSString *openStatus1;

@end

@implementation MOFinishDoDetail_DoingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
    
    [self initData];
}

-(void)initData
{
    self.dataArray = [NSMutableArray array];
    NSArray *titleArr = @[@"新疆税务局收文处理单",@"缓急:",@"标题:",@"密级:",@"主办单位:",@"总收支号:",@"办理类型:",@"来文字号:",@"收文日期:",@"限办日期:",@"来文单位:",@"会办单位:",@"拟办意见:",@"附注:"];
    NSArray *valueArr = @[@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@""];
    for (int i = 0; i<titleArr.count; i++) {
        MOWaitDoDetail_DoingModel *model = [[MOWaitDoDetail_DoingModel alloc]init];
        model.nameStr = titleArr[i];
        model.valueStr = valueArr[i];
        if (i==0) {
            model.isCenter = @"1";
        }
        [self.dataArray addObject:model];
    }
    [self.tableView reloadData];
}

-(void)setGetDataArray:(NSMutableArray *)getDataArray
{
    self.dataArray = [NSMutableArray array];
    self.dataArray = getDataArray;
    [self.tableView reloadData];
}

-(void)setFinishDoDetail_Doing_AgressArray:(NSMutableArray *)finishDoDetail_Doing_AgressArray
{
    _finishDoDetail_Doing_AgressArray = finishDoDetail_Doing_AgressArray;
    [self.tableView reloadData];
}

-(void)setFinishDoDetail_Doing_IdeaArray:(NSMutableArray *)finishDoDetail_Doing_IdeaArray
{
    _finishDoDetail_Doing_IdeaArray = finishDoDetail_Doing_IdeaArray;
    [self.tableView reloadData];
}

-(void)clickShowIdeaButton:(UIButton *)sender
{
    if ([self.openStatus integerValue]==1) {
        self.openStatus = @"0";
    }else{
        self.openStatus = @"1";
    }
    [self.tableView reloadData];
}

-(void)clickShowAgreeButton:(UIButton *)sender
{
    if ([self.openStatus1 integerValue]==1) {
        self.openStatus1 = @"0";
    }else{
        self.openStatus1 = @"1";
    }
    [self.tableView reloadData];
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if ([self.waitModel.wdlx isEqualToString:@"收文处理单"]) {//收文
        return 3;
    }else{
        return 1;
    }
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([self.waitModel.wdlx isEqualToString:@"收文处理单"]) {//收文
        if (section==0) {
            return self.dataArray.count;
        }else if(section==1){
            if ([self.openStatus1 integerValue]==1) {
                return self.finishDoDetail_Doing_AgressArray.count;
            }else{
                return 0;
            }
        }else{
            if ([self.openStatus integerValue]==1) {
                return self.finishDoDetail_Doing_IdeaArray.count;
            }else{
                return 0;
            }
        }
    }else{
        return self.dataArray.count;
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.waitModel.wdlx isEqualToString:@"收文处理单"]) {//收文
        if (indexPath.section==0) {
            MOWaitDoDetail_DoingViewCell *cell = [MOWaitDoDetail_DoingViewCell cellWithTableView:tableView andIndexPath:indexPath];
            cell.model = self.dataArray[indexPath.row];
            
            return cell;
        }else if (indexPath.section==1){
            MOWaitDoDetail_Doing_ideaViewCell *cell = [MOWaitDoDetail_Doing_ideaViewCell cellWithTableView:tableView andIndexPath:indexPath];
            cell.dataDic = self.finishDoDetail_Doing_AgressArray[indexPath.row];
            return cell;
        }else{
            MOWaitDoDetail_Doing_ideaViewCell *cell = [MOWaitDoDetail_Doing_ideaViewCell cellWithTableView:tableView andIndexPath:indexPath];
            cell.dataDic = self.finishDoDetail_Doing_IdeaArray[indexPath.row];
            return cell;
        }
    }else{
        MOWaitDoDetail_DoingViewCell *cell = [MOWaitDoDetail_DoingViewCell cellWithTableView:tableView andIndexPath:indexPath];
        cell.model = self.dataArray[indexPath.row];
        
        return cell;
    }
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.waitModel.wdlx isEqualToString:@"收文处理单"]) {//收文
        if (indexPath.section==0) {
            return [MOWaitDoDetail_DoingViewCell heightForMOWaitDoDetail_DoingViewCellAndModel:self.dataArray[indexPath.row]];
        }else if (indexPath.section==1){
            return 113;
        }else{
            return 113;
        }
    }else{
        return [MOWaitDoDetail_DoingViewCell heightForMOWaitDoDetail_DoingViewCellAndModel:self.dataArray[indexPath.row]];
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return 10;
    }else if (section==1){
        return kHConversions(54) + 10;
    }else{
        return kHConversions(54) + 10;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return nil;
    }else if (section==1){
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHConversions(54) + 10)];
        backView.backgroundColor = KGrayColor_ededed;
        
        UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, kHConversions(54))];
        [contentView setBackgroundColor:[UIColor whiteColor]];
        [backView addSubview:contentView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 100, kHConversions(54))];
        label.textColor = KBlackColor_2A2A2A;
        label.font = FONT_SIZE(15);
        label.text = @"领导批示：";
        [contentView addSubview:label];
        
        UIButton *selectedButton = [[UIButton alloc]initWithFrame:CGRectMake(label.right, 0, SCREEN_WIDTH - label.right - 20, kHConversions(54))];
        [selectedButton setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentRight)];
        [selectedButton addTarget:self action:@selector(clickShowAgreeButton:) forControlEvents:UIControlEventTouchUpInside];
        if ([self.openStatus1 integerValue]==1) {
            [selectedButton setImage:IMAGE(@"top_notice") forState:UIControlStateNormal];
        }else{
            [selectedButton setImage:IMAGE(@"down_notice") forState:UIControlStateNormal];
        }
        [contentView addSubview:selectedButton];
        
        
        return backView;
    }else{
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHConversions(54)+10)];
        backView.backgroundColor = KGrayColor_ededed;
        
        UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, kHConversions(54))];
        [contentView setBackgroundColor:[UIColor whiteColor]];
        [backView addSubview:contentView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 100, kHConversions(54))];
        label.textColor = KBlackColor_2A2A2A;
        label.font = FONT_SIZE(15);
        label.text = @"意见：";
        [contentView addSubview:label];
        
        UIButton *selectedButton = [[UIButton alloc]initWithFrame:CGRectMake(label.right, 0, SCREEN_WIDTH - label.right - 20, kHConversions(54))];
        [selectedButton setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentRight)];
        [selectedButton addTarget:self action:@selector(clickShowIdeaButton:) forControlEvents:UIControlEventTouchUpInside];
        if ([self.openStatus integerValue]==1) {
            [selectedButton setImage:IMAGE(@"top_notice") forState:UIControlStateNormal];
        }else{
            [selectedButton setImage:IMAGE(@"down_notice") forState:UIControlStateNormal];
        }
        [contentView addSubview:selectedButton];
        
        
        return backView;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

#pragma mark - 设置顶头分割线
-(void)viewDidLayoutSubviews {
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])  {
        if (@available(iOS 8.0, *)) {
            [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
        } else {
            // Fallback on earlier versions
        }
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        if (@available(iOS 8.0, *)) {
            [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
        } else {
            // Fallback on earlier versions
        }
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}


#pragma mark -- 懒加载
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - StatusBarAndNavigationBarHeight - 41) style:(UITableViewStyleGrouped)];
        _tableView.backgroundColor = KGrayColor_ededed;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}



@end
